package com.wangsan.study.sc.test.hello.simple;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;

public class SayHelloCommand extends HystrixCommand<String> {
    private final String underName;

    public SayHelloCommand(String name) {
        // builder for HystrixCommand
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("HelloServiceGroup"))
                .andCommandPropertiesDefaults(
                        HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(500)));
        // unmutable
        underName = new String(name);

    }

    @Override
    protected String getFallback() {
        return String.format("[FallBack]Hello %s!", underName);
    }

    @Override
    protected String run() throws Exception {
        // TimeOut
        Thread.sleep(600);
        return String.format("Hello %s!", underName);
    }
}